/***************************************************
> Copyright (C) 2024 ==KINGYI== All rights reserved.
> File Name: queue.c
> Author:cjy
> Mail: 
> Created Time: 2024年08月08日 星期四 16时33分24秒
***************************************************/

#include "queue.h"

// 创建头节点 
struct queue *create_queue(){
	struct queue * head = (struct queue *) malloc(sizeof(struct queue));
	memset(head,0,sizeof(struct queue));
	head->next = NULL;
	return head;
}
// 在链表中添加数据(尾插)
void push(int data, struct queue *que) {
    struct queue *p = que;
    struct queue *point = malloc(sizeof(struct queue));
    memset(point, 0, sizeof(struct queue));
    
    if (p->next == NULL) {
        p->next = point;
        point->data = data;
        point->next = NULL;
    } else {
        while (p->next != NULL) { 
            p = p->next;
        }
        p->next = point;
        point->data = data;
        point->next = NULL;
    }
    printf("ok\n");
}

// 把数据展示出来
int front(struct queue *que){
	int data = 0;
	struct queue *p = que->next;
	data = p->data;
	return data;	
}
// 删除数据(头删)
void pop(struct queue *que) {
    if (que->next == NULL) {
        return;  
    }

    struct queue *temp = que->next;
    que->next = temp->next;  
    free(temp);              
    temp = NULL;             
}

// 遍历链表看链表中值的个数
int size(struct queue *que){
struct queue *head = que->next;
	if(head == NULL) {
	        return 0;
	}
	int count = 0;
	while(head != NULL) {
            count ++;
            head = head->next;
        }	
	return count;
}
// 判断链表是否为空
int isempty(struct queue *que){
	struct queue *head = que->next;
	if(head == NULL) {
	        return 0;
	}
	
	return -1;
}
	
